package com.jinke.game;

import com.jinke.tank.Tank;

import java.awt.*;

/**
 * 子弹类
 */
public class Bullet {
    //子弹的默认速度为坦克的两倍
    public static final int DEFAULT_SPEED = Tank.DEFAULT_SPEED<<1;
    //子弹的默认半径为4
    public static final int RADIUS = 4;

    private int x, y;
    private int speed = DEFAULT_SPEED;
    private int dir;
    private int atk;
    private Color color;

    /**
     * 创建一个炮弹对象
     * @param x 子弹的x坐标
     * @param y 子弹的y坐标
     * @param dir 子弹的炮口方向
     * @param atk 子弹的攻击力
     */
    public Bullet(int x, int y, int dir, int atk,Color color) {
        this.x = x;
        this.y = y;
        this.dir = dir;
        this.atk = atk;
        this.color = color;
    }

    public Bullet() {
    }

    /**
     * 炮弹自身的绘制方法
     * @param g 系统提供的画笔
     */
    public void drawBullet(Graphics g) {
        logic();
        g.setColor(color);
        // 修改为使用直径
        g.fillOval(x - RADIUS, y - RADIUS, RADIUS << 1, RADIUS << 1);

    }

    /**
     * 炮弹的逻辑方法
     */
    private void logic() {

        switch ( dir){
            case Tank.DIR_UP:
                y -= speed;
                break;
            case Tank.DIR_DOWN:
                y += speed;
                break;
            case Tank.DIR_LEFT:
                x -= speed;
                break;
            case Tank.DIR_RIGHT:
                x += speed;
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getDir() {
        return dir;
    }

    public void setDir(int dir) {
        this.dir = dir;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    /**
     * 重置炮弹
     *
     * @param x           炮弹的x坐标
     * @param y           炮弹的y坐标
     * @param dir         炮弹的炮口方向
     * @param atk         炮弹的攻击力
     * @param bulletColor
     */
    public void reset(int x, int y, int dir, int atk, Color bulletColor) {
        this.x = x;
        this.y = y;
        this.dir = dir;
        this.atk = atk;
        this.color = bulletColor;
    }
}
